<?php

use app\admin\middleware\CheckCache;
use app\admin\model\NavItem;
use app\admin\service\interface\CacheService;
use app\admin\service\NavServiceImpl;
use PHPUnit\Framework\TestCase;
use think\App;
use think\facade\Cache;
use think\facade\Db;

use function PHPUnit\Framework\assertTrue;

class NavTest extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        $http = (new App())->http;

        $response = $http->run();
    }
    function tearDown(): void
    {
        assertTrue(true);
    }

    public function testRef()
    {
        $arr=[1,2,3];
        // $this->aaa($arr);
        // var_dump($arr);
        foreach ($arr as $key => &$value) {
            # code...
            $this->bbb($value);
        }
        var_dump($arr);
    }
    private function aaa(&$arr)
    {
        $arr[]='aaa';
    }
    private function bbb(&$aa)
    {
        $aa='bbb';
    }

    public function testSelect()
    {
        $list = NavItem::field("id,name,path")->column("id,name,path","tag");
        dump($list);
    }
    public function testBuildList()
    {
        $service = new NavServiceImpl();
        $res = $service->list();
        dump($res);
    }
    public function testBuildCache()
    {
        $service = new NavServiceImpl();
        $res = $service->buildCacheData();
        dump($res['groups']);
    }
    public function testJoin()
    {
        $res = Db::table("nav_group")->alias("a")->join("nav_item b","a.id = b.group_id")->field("a.name as a_name,b.*")->select();
        dump($res);
    }
    public function testStr()
    {
        $str = 'aaa/bbb';
        $arr = explode('/', $str);
        var_dump($arr);
        $str = 'aaa/';
        $arr = explode('/', $str);
        var_dump($arr);
        $str = 'aaa';
        $arr = explode('/', $str);
        var_dump($arr);
        $str = '';
        $arr = explode('/', $str);
        var_dump($arr);
    }
    public function testNav()
    {
        $GLOBALS["nav"] = Cache::get(CacheService::CACHE_NAV);
        $GLOBALS["config"] = Cache::get(CacheService::CACHE_CONFIG);
        $m=new CheckCache();
        $res = $m->buildCrumbs("user/add");
        var_dump($res);
    }
    public function testArr()
    {
        $arr=["a"=>1,"b"=>2];
        $aa=$arr['c'];
        var_dump($aa);  
    }
  }
